/*
 * @Author: silence
 * @Date: 2023-07-04 16:51:17
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-08-16 15:05:13
 * @Description: 电站详情——实时数据
 */
import 'package:ems_neutral_app/utils/color/ColorUtils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../Mine/Language/SilLocalizations/SilLocalizations.dart';
import '../Controller/PowerStationDetailController.dart';

class PsDetailRealTimeView extends StatefulWidget {
  const PsDetailRealTimeView({super.key});

  @override
  State<PsDetailRealTimeView> createState() => _PsDetailRealTimeViewState();
}

class _PsDetailRealTimeViewState extends State<PsDetailRealTimeView> {
  PowerStationDetailController _controller =
      Get.put(PowerStationDetailController());

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 20.w),
      child: contentView(),
    );
  }

  contentView() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        /// 标题
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            SilButton(
              imgPath: 'imgs/home/home_money.png',
              imgHeight: 25.w,
              imgWidth: 25.w,
              title: LangOf(context)?.dz_zzw?.rd,
              titleColor: ColorUtils.color_font_main,
              fontSize: 17.sp,
              imagePosition: ImagePosition.Left,
            ),
            Container(),
          ],
        ),

        /// PV1电压/PV2电压/输出电流
        upInfoView(),

        /// 输出功率/电池电压
        Container(
          margin: EdgeInsets.only(top: 20.w),
          child: bottomInfoView(),
        )
      ],
    );
  }

  /// PV1电压/PV2电压/输出电流
  upInfoView() {
    List<String?> itemTitles = [];
    itemTitles.add(LangOf(context)?.dz_zzw?.pv1); // PV1电压
    itemTitles.add(LangOf(context)?.dz_zzw?.pv2); // PV2电压
    itemTitles.add(LangOf(context)?.dz_zzw?.current); // 输出电流

    List<String?> itemValues = ['0.0', '0.0', '0'];

    itemValues[0] = _controller.powerStationEntity.value.pv_one;
    itemValues[1] = _controller.powerStationEntity.value.pv_two;

    double outputCurrent =
        double.parse(_controller.powerStationEntity.value.outputCurrentStr);
    double pvCurrent =
        double.parse(_controller.powerStationEntity.value.pvTwoCurrentStr);

    itemValues[2] = "${outputCurrent + pvCurrent}";

    List<Widget> itemWidgets = [];
    for (var i = 0; i < itemTitles.length; i++) {
      SilText titleWidget = SilText(itemTitles[i],
          color: ColorUtils.color_font_main, fontSize: 13.sp, maxLines: 0);

      Widget valueWidget = SilText("${itemValues[i]}",
          color: ColorUtils.color_font_main, fontSize: 13.sp, maxLines: 0);

      itemWidgets.add(SilTextIconButton(
        titleWidget,
        valueWidget,
        space: 20.w,
        imagePosition: ImagePosition.Down,
      ));
    }

    return Container(
      margin: EdgeInsets.only(top: 20.w),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: itemWidgets),
    );
  }

  /// 输出功率/电池电压
  bottomInfoView() {
    List<String?> itemTitles = [];
    itemTitles.add(LangOf(context)?.dz_zzw?.power); // 输出功率
    itemTitles.add(LangOf(context)?.dz_zzw?.voltage); // 电池电压
    itemTitles.add(' ');

    List<String?> itemValues = ['0.0', '0.0', ' '];
    itemValues[0] = _controller.powerStationEntity.value.real_power;
    itemValues[1] = _controller.powerStationEntity.value.batteryVoltageStr;
    itemValues[2] = ' ';

    List<Widget> itemWidgets = [];
    for (var i = 0; i < itemTitles.length; i++) {
      SilText titleWidget = SilText(itemTitles[i],
          color: ColorUtils.color_font_main, fontSize: 13.sp, maxLines: 0);

      Widget valueWidget = SilText("${itemValues[i]}",
          color: ColorUtils.color_font_main, fontSize: 13.sp, maxLines: 0);

      itemWidgets.add(SilTextIconButton(
        titleWidget,
        valueWidget,
        space: 20.w,
        imagePosition: ImagePosition.Down,
      ));
    }

    return Container(
      margin: EdgeInsets.only(top: 20.w),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: itemWidgets),
    );
  }
}
